<?php

namespace App\Validator\Admin\Rbac;

use App\Constants\Rbac\RouteCode;
use App\Validator\BaseValidator;
use Hyperf\Validation\Rule;

class RouteValidator extends BaseValidator
{

    protected array $attr = [
        'id' => '路由id',
        'ids' => '路由id',
        'pid' => '上级id',
        'type' => '路由类型',
        'name' => '角色名称',
        'path' => '路径',
    ];

    public function add(array $data)
    {
        return $this->validate($data,[
            'pid' => ['required','integer','min:0',],
            'type' => ['required','integer',Rule::in(RouteCode::validType()),],
            'name' => ['required','string',],
            'path' => ['string',],
        ]);
    }

    public function update(array $data)
    {
        return $this->validate($data,[
            'id' => ['required','integer','min:1',],
            'pid' => ['required','integer','min:0',],
            'type' => ['required','integer',Rule::in(RouteCode::validType()),],
            'name' => ['required','string',],
            'path' => ['string',],
        ]);
    }

    public function del($data)
    {
        return $this->validate($data,[
            'ids' => ['required','array','min:1'],
            'ids.*' => ['required','integer','min:1'],
        ]);
    }
}
